提前感谢所有看这个问题的人,尤其是那些试图回答的人!这个网站对我帮助很大!
我目前在我的 Android 4.2.2 应用程序中遇到以下错误。以下是日志:
09-09 01:14:27.008: D/dalvikvm(9008): newInstance failed: p0 i0 [0 a1
09-09 01:14:27.008: D/AndroidRuntime(9008): Shutting down VM
09-09 01:14:27.008: W/dalvikvm(9008): threadid=1: thread exiting with uncaught exception (group=0x41173ac8)
09-09 01:14:27.018: E/AndroidRuntime(9008): FATAL EXCEPTION: main
09-09 01:14:27.018: E/AndroidRuntime(9008): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.pocketbotanist/com.pocketbotanist.HomeScreen}: java.lang.InstantiationException: can't instantiate class com.pocketbotanist.HomeScreen
09-09 01:14:27.018: E/AndroidRuntime(9008): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2173)
09-09 01:14:27.018: E/AndroidRuntime(9008): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2297)
09-09 01:14:27.018: E/AndroidRuntime(9008): at android.app.ActivityThread.access$700(ActivityThread.java:152)
09-09 01:14:27.018: E/AndroidRuntime(9008): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1282)
09-09 01:14:27.018: E/AndroidRuntime(9008): at android.os.Handler.dispatchMessage(Handler.java:99)
09-09 01:14:27.018: E/AndroidRuntime(9008): at android.os.Looper.loop(Looper.java:137)
09-09 01:14:27.018: E/AndroidRuntime(9008): at android.app.ActivityThread.main(ActivityThread.java:5328)
09-09 01:14:27.018: E/AndroidRuntime(9008): at java.lang.reflect.Method.invokeNative(Native Method)
09-09 01:14:27.018: E/AndroidRuntime(9008): at java.lang.reflect.Method.invoke(Method.java:511)
09-09 01:14:27.018: E/AndroidRuntime(9008): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
09-09 01:14:27.018: E/AndroidRuntime(9008): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
09-09 01:14:27.018: E/AndroidRuntime(9008): at dalvik.system.NativeStart.main(Native Method)
09-09 01:14:27.018: E/AndroidRuntime(9008): Caused by: java.lang.InstantiationException: can't instantiate class com.pocketbotanist.HomeScreen
09-09 01:14:27.018: E/AndroidRuntime(9008): at java.lang.Class.newInstanceImpl(Native Method)
09-09 01:14:27.018: E/AndroidRuntime(9008): at java.lang.Class.newInstance(Class.java:1319)
09-09 01:14:27.018: E/AndroidRuntime(9008): at android.app.Instrumentation.newActivity(Instrumentation.java:1071)
09-09 01:14:27.018: E/AndroidRuntime(9008): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2164)
09-09 01:14:27.018: E/AndroidRuntime(9008): ... 11 more
我已经尝试清理一个项目,尝试修复我在其他地方看到的 Android 私有(private)库,并检查了我的包名称(除非我遗漏了什么,我可能是这样!)。这是 homescreen.java:
package com.pocketbotanist;
import java.io.File;
import android.app.ListActivity;
import android.app.LoaderManager;
import android.content.Intent;
import android.content.Loader;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.Spinner;
import com.pocketbotanist.contentprovider.MyEntryContentProvider;
import com.pocketbotanist.database.EntryTable;
public abstract class HomeScreen extends ListActivity implements LoaderManager.LoaderCallbacks<Cursor> {
private static final int DELETE_ID = Menu.FIRST + 1;
// private Cursor cursor;
private SimpleCursorAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_screen);
this.getListView().setDividerHeight(2);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
//Initial folder creation code
File appDirectory = new File(Environment.getExternalStorageDirectory().toString()+"/Pocket Botanist/");
if (!appDirectory.exists()){
appDirectory.mkdir();
}
//Drop down list code
Spinner spinner = (Spinner) findViewById(R.id.action_spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.action_list, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
fillData();
//View listItem=(View)((Menu) this.getListView()).getItem(0);
registerForContextMenu(getListView());
if (adapter.isEmpty())
System.out.println("IT'S EMPTY");
String[] projection = { EntryTable.COLUMN_CUSTOMID };
long info = adapter.getItemId(0);
Uri uri = Uri.parse(MyEntryContentProvider.CONTENT_URI + "/"
+ info);
Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
cursor.moveToFirst();
System.out.println((cursor.getString(cursor
.getColumnIndexOrThrow(EntryTable.COLUMN_CUSTOMID))));
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
switch (item.getItemId()) {
case DELETE_ID:
String[] projection = { EntryTable.COLUMN_PHOTOS };
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
.getMenuInfo();
Uri uri = Uri.parse(MyEntryContentProvider.CONTENT_URI + "/"
+ info.id);
Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
cursor.moveToFirst();
File temp = new File(cursor.getString(cursor
.getColumnIndexOrThrow(EntryTable.COLUMN_PHOTOS)));
if(temp.exists()){
File[] files = temp.listFiles();
for(int i = 0; i < files.length; i++){
files[i].delete();
}
temp.delete();
}
getContentResolver().delete(uri, null, null);
fillData();
return true;
}
return super.onContextItemSelected(item);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_home_screen, menu);
//SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.menu_settings:
settCall();
return true;
case R.id.menu_map:
map1_3();
return true;
case R.id.menu_edit:
entryScreen("New Entry");
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public void entryScreen(String t){
Intent intent = new Intent(this, EntryScreen.class);
intent.putExtra("passer", t);
startActivity(intent);
}
public void settCall(){
Intent sett = new Intent(this,SettingsActivity.class);
startActivity(sett);
}
public void map1_3(){
Intent map13 = new Intent(this,Entrymap_1_3.class);
startActivity(map13);
}
// Opens the second activity if an entry is clicked
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Intent i = new Intent(this, EntryScreen.class);
Uri itemUri = Uri.parse(MyEntryContentProvider.CONTENT_URI + "/" + id);
i.putExtra(MyEntryContentProvider.CONTENT_ITEM_TYPE, itemUri);
startActivity(i);
}
//@Override
//When we create the loader we're going to get the projection for the ID, customID, species name, and time columns
//(insures that these exist within the database)
//then we create our cursor loader which will be responsible for loading data from the database
//using the projection and our content provider
/* public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
String[] projection = { EntryTable.COLUMN_ID, EntryTable.COLUMN_CUSTOMID, EntryTable.COLUMN_SPECIES, EntryTable.COLUMN_TIME, EntryTable.COLUMN_PHOTOS, EntryTable.COLUMN_PHOTO };
CursorLoader cursor = new CursorLoader(this,
MyEntryContentProvider.CONTENT_URI, projection, null, null, null);
if (cursor != null) {
((Cursor) cursor).moveToFirst();
}
return cursor;
} */
private void fillData() {
// Fields from the database (projection)
String[] from = new String[] { EntryTable.COLUMN_CUSTOMID, EntryTable.COLUMN_SPECIES , EntryTable.COLUMN_TIME, EntryTable.COLUMN_PHOTO};
// Fields on the UI to which we map
int[] to = new int[] { R.id.customidlabel, R.id.namelabel, R.id.timelabel, R.id.imageView };
getLoaderManager().initLoader(1, null, this); //changed to 1
adapter = new SimpleCursorAdapter(this, R.layout.list_row, null, from, to, 0);
setListAdapter(adapter);
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.add(0, DELETE_ID, 0, R.string.menu_delete);
}
@Override
public void onLoadFinished(Loader<Cursor> arg0, Cursor data) {
adapter.swapCursor(data);
}
@Override
public void onLoaderReset(Loader<Cursor> arg0) {
adapter.swapCursor(null);
}
}
我知道问题可能出在这里,所以这也是我的 AndroidManifest.xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pocketbotanist"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<permission
android:name="com.pocketbotanist.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.pocketbotanist.permission.MAPS_RECEIVE"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:configChanges="keyboardHidden|orientation" >
<activity
android:name="com.pocketbotanist.HomeScreen"
android:label="@string/main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.pocketbotanist.EntryScreen"
android:label="@string/title_activity_entry_screen"
android:windowSoftInputMode="stateHidden"
>
</activity>
<activity
android:name="com.pocketbotanist.SettingsActivity"
android:label="@string/title_activity_settings" >
</activity>
<activity
android:name="com.pocketbotanist.ManualLocationActivity"
android:label="@string/title_activity_manual_location" >
</activity>
<activity
android:name="com.pocketbotanist.Entrymap_1_3"
android:label="@string/title_activity_entrymap_1_3" >
</activity>
<activity
android:name="com.pocketbotanist.Location_2_3"
android:label="@string/title_location_2_3" >
</activity>
<activity
android:name="com.pocketbotanist.Mapfragmentpreview"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/title_activity_mapfragmentpreview"
android:theme="@style/FullscreenTheme" >
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="(removing key for security reasons)" />
<uses-library
android:name="com.google.android.maps"
android:required="true" />
<provider
android:name="com.pocketbotanist.contentprovider.MyEntryContentProvider"
android:authorities="com.pocketbotanist.contentprovider"
android:exported="false">
</provider>
</application>
</manifest>
有没有人有任何想法/建议?再次提前致谢!
最佳答案
根据定义,抽象类是不可实例化的。
改变
public abstract class HomeScreen extends ListActivity
到
public class HomeScreen extends ListActivity
关于java - 无法实例化 Activity ComponentInfo 无法实例化类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18692537/
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
我正在查看instance_variable_set的文档并看到给出的示例代码是这样做的:obj.instance_variable_set(:@instnc_var,"valuefortheinstancevariable")然后允许您在类的任何实例方法中以@instnc_var的形式访问该变量。我想知道为什么在@instnc_var之前需要一个冒号:。冒号有什么作用? 最佳答案 我的第一直觉是告诉你不要使用instance_variable_set除非你真的知道你用它做什么。它本质上是一种元编程工具或绕过实例变量可见性的黑客攻击
在我的应用程序中,我需要能够找到所有数字子字符串,然后扫描每个子字符串,找到第一个匹配范围(例如5到15之间)的子字符串,并将该实例替换为另一个字符串“X”。我的测试字符串s="1foo100bar10gee1"我的初始模式是1个或多个数字的任何字符串,例如,re=Regexp.new(/\d+/)matches=s.scan(re)给出["1","100","10","1"]如果我想用“X”替换第N个匹配项,并且只替换第N个匹配项,我该怎么做?例如,如果我想替换第三个匹配项“10”(匹配项[2]),我不能只说s[matches[2]]="X"因为它做了两次替换“1fooX0barXg
我正在尝试在我的centos服务器上安装therubyracer,但遇到了麻烦。$geminstalltherubyracerBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtherubyracer:ERROR:Failedtobuildgemnativeextension./usr/local/rvm/rubies/ruby-1.9.3-p125/bin/rubyextconf.rbcheckingformain()in-lpthread...yescheckingforv8.h...no***e
我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳
我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/
我在pry中定义了一个函数:to_s,但我无法调用它。这个方法去哪里了,怎么调用?pry(main)>defto_spry(main)*'hello'pry(main)*endpry(main)>to_s=>"main"我的ruby版本是2.1.2看了一些答案和搜索后,我认为我得到了正确的答案:这个方法用在什么地方?在irb或pry中定义方法时,会转到Object.instance_methods[1]pry(main)>defto_s[1]pry(main)*'hello'[1]pry(main)*end=>:to_s[2]pry(main)>defhello[2]pry(main)
我使用的是Firefox版本36.0.1和Selenium-Webdrivergem版本2.45.0。我能够创建Firefox实例,但无法使用脚本继续进行进一步的操作无法在60秒内获得稳定的Firefox连接(127.0.0.1:7055)错误。有人能帮帮我吗? 最佳答案 我遇到了同样的问题。降级到firefoxv33后一切正常。您可以找到旧版本here 关于ruby-无法在60秒内获得稳定的Firefox连接(127.0.0.1:7055),我们在StackOverflow上找到一个类