我很难解决代码中的一些问题。我在手机上测试了它,效果很好。但是如果我在Galaxy Tab 4上测试它,它会在onCreate()方法中给我java.lang.NullPointerException和未知来源。
public class MainActivity extends ActionBarActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainxml);
Button butns = (Button) findViewById(R.id.sb1);
butns.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(getApplicationContext(), Sub1.class);
startActivity(intent);
}
});
Button butnss = (Button) findViewById(R.id.sb2);
butnss.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(getApplicationContext(), Sub2.class);
startActivity(intent);
}
});
Button butsns = (Button) findViewById(R.id.sb3);
butsns.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(getApplicationContext(), Sub3.class);
startActivity(intent);
}
});
Button quiz = (Button) findViewById(R.id.quiz);
quiz.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(getApplicationContext(), QuizActivity.class);
startActivity(intent);
}
});
ImageButton butsn1s = (ImageButton) findViewById(R.id.info);
butsn1s.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(getApplicationContext(), Info.class);
startActivity(intent);
}
});
ImageButton btn = (ImageButton) findViewById(R.id.fb);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent myWebLink = new Intent(Intent.ACTION_VIEW);
myWebLink.setData(Uri.parse("https://www.facebook.com/pages/SharpMind-software/540118499454551?ref=hl"));
startActivity(myWebLink);
}
});
ImageButton cnt = (ImageButton) findViewById(R.id.count);
cnt.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent count = new Intent(getApplicationContext(),Count.class);
startActivity(count);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
switch (item.getItemId()) {
case R.id.settings:
Intent settings = new Intent(getApplicationContext(), Settings.class);
startActivity(settings);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
以下是错误:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sharpmind.Romana_pentru_BAC_PRO/com.sharpmind.Romana_pentru_BAC_PRO.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2331)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
at android.app.ActivityThread.access$900(ActivityThread.java:169)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1277)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5479)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.sharpmind.Romana_pentru_BAC_PRO.MainActivity.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:5451)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
... 11 more
感谢。 祝你有愉快的一天!
答案 0 :(得分:0)
尝试更改com.android.wifi
,碰巧android不接受某些包名。我不知道为什么,但它甚至不接受com
几天前面临同样的问题并使用不同的包名称
成功解决了 并确保您使用“小写字母”并在首发中添加List<string> words = Review.Split(" ").ToList();
foreach(string stopWord in arrStopWord)
words.Remove(stopWord);
string result = String.Join(" ", words);
。
答案 1 :(得分:0)
Thanks for help, now if the problem appears again I will know what to try. I've found it. My main.xml layout large resource was not containing one of the buttons declared above. I might look like a fool now, but it happens. Thanks again for answers and comments.