03-23 23:28:04.490: I/dalvikvm(275): Could not find method android.content.pm.PackageManager.getActivityLogo, referenced from method android.support.v7.internal.widget.ActionBarView.<init>
您好!运行我的代码ADT时出现上述错误:22.6.1 SDK:4.4.2 我不知道问题是什么,我是Android开发的新手。我试图在youtube上运行mybringback提供的代码。但它没有运行。
我提到了一个显示背景更改代码的帖子,但这也不起作用。
改变有效,但又出现了一些错误:
03-23 16:13:24.390: D/AndroidRuntime(947): Shutting down VM
03-23 16:13:24.390: W/dalvikvm(947): threadid=1: thread exiting with uncaught exception (group=0xb1a9cba8)
03-23 16:13:24.410: E/AndroidRuntime(947): FATAL EXCEPTION: main
03-23 16:13:24.410: E/AndroidRuntime(947): Process: com.example.myfirstapp, PID: 947
03-23 16:13:24.410: E/AndroidRuntime(947): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myfirstapp/com.example.myfirstapp.StartingPoint}: java.lang.NullPointerException
03-23 16:13:24.410: E/AndroidRuntime(947): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
03-23 16:13:24.410: E/AndroidRuntime(947): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
03-23 16:13:24.410: E/AndroidRuntime(947): at android.app.ActivityThread.access$800(ActivityThread.java:135)
03-23 16:13:24.410: E/AndroidRuntime(947): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
03-23 16:13:24.410: E/AndroidRuntime(947): at android.os.Handler.dispatchMessage(Handler.java:102)
03-23 16:13:24.410: E/AndroidRuntime(947): at android.os.Looper.loop(Looper.java:136)
03-23 16:13:24.410: E/AndroidRuntime(947): at android.app.ActivityThread.main(ActivityThread.java:5017)
03-23 16:13:24.410: E/AndroidRuntime(947): at java.lang.reflect.Method.invokeNative(Native Method)
03-23 16:13:24.410: E/AndroidRuntime(947): at java.lang.reflect.Method.invoke(Method.java:515)
03-23 16:13:24.410: E/AndroidRuntime(947): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-23 16:13:24.410: E/AndroidRuntime(947): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-23 16:13:24.410: E/AndroidRuntime(947): at dalvik.system.NativeStart.main(Native Method)
03-23 16:13:24.410: E/AndroidRuntime(947): Caused by: java.lang.NullPointerException
03-23 16:13:24.410: E/AndroidRuntime(947): at com.example.myfirstapp.StartingPoint.onCreate(StartingPoint.java:36)
03-23 16:13:24.410: E/AndroidRuntime(947): at android.app.Activity.performCreate(Activity.java:5231)
03-23 16:13:24.410: E/AndroidRuntime(947): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
03-23 16:13:24.410: E/AndroidRuntime(947): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
03-23 16:13:24.410: E/AndroidRuntime(947): ... 11 more
03-23 16:13:33.790: I/Process(947): Sending signal. PID: 947 SIG: 9
03-23 16:18:06.983: D/AndroidRuntime(1155): Shutting down VM
03-23 16:18:06.983: W/dalvikvm(1155): threadid=1: thread exiting with uncaught exception (group=0xb1a9cba8)
03-23 16:18:07.003: E/AndroidRuntime(1155): FATAL EXCEPTION: main
03-23 16:18:07.003: E/AndroidRuntime(1155): Process: com.example.myfirstapp, PID: 1155
03-23 16:18:07.003: E/AndroidRuntime(1155): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myfirstapp/com.example.myfirstapp.StartingPoint}: java.lang.NullPointerException
03-23 16:18:07.003: E/AndroidRuntime(1155): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
03-23 16:18:07.003: E/AndroidRuntime(1155): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
03-23 16:18:07.003: E/AndroidRuntime(1155): at android.app.ActivityThread.access$800(ActivityThread.java:135)
03-23 16:18:07.003: E/AndroidRuntime(1155): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
03-23 16:18:07.003: E/AndroidRuntime(1155): at android.os.Handler.dispatchMessage(Handler.java:102)
03-23 16:18:07.003: E/AndroidRuntime(1155): at android.os.Looper.loop(Looper.java:136)
03-23 16:18:07.003: E/AndroidRuntime(1155): at android.app.ActivityThread.main(ActivityThread.java:5017)
03-23 16:18:07.003: E/AndroidRuntime(1155): at java.lang.reflect.Method.invokeNative(Native Method)
03-23 16:18:07.003: E/AndroidRuntime(1155): at java.lang.reflect.Method.invoke(Method.java:515)
03-23 16:18:07.003: E/AndroidRuntime(1155): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-23 16:18:07.003: E/AndroidRuntime(1155): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-23 16:18:07.003: E/AndroidRuntime(1155): at dalvik.system.NativeStart.main(Native Method)
03-23 16:18:07.003: E/AndroidRuntime(1155): Caused by: java.lang.NullPointerException
03-23 16:18:07.003: E/AndroidRuntime(1155): at com.example.myfirstapp.StartingPoint.onCreate(StartingPoint.java:36)
03-23 16:18:07.003: E/AndroidRuntime(1155): at android.app.Activity.performCreate(Activity.java:5231)
03-23 16:18:07.003: E/AndroidRuntime(1155): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
03-23 16:18:07.003: E/AndroidRuntime(1155): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
03-23 16:18:07.003: E/AndroidRuntime(1155): ... 11 more
03-23 16:23:07.463: I/Process(1155): Sending signal. PID: 1155 SIG: 9
代码: 的 main.xml中
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your total is:"
android:id="@+id/tvdisplay"
/>
<Button
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Add one"
android:textSize="40sp"
android:id="@+id/badd"
/>
<Button
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Subtract one"
android:textSize="40sp"
android:id="@+id/bsub"
/>
</LinearLayout>
mainactivity.java
package com.example.mysecondapp;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.os.Build;
public class MainActivity extends ActionBarActivity {
int counter;
Button add,sub;
TextView display;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
display=(TextView) findViewById(R.id.tvdisplay);
add=(Button) findViewById(R.id.badd);
sub=(Button) findViewById(R.id.bsub);
add.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
counter++;
display.setText("Your total is" + counter);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
return rootView;
}
}
}
}
答案 0 :(得分:0)
此来电是introduced in API level 9。这意味着您的应用程序清单需要minSdkVersion
值至少为9。
确保您的AndroidManifest.xml具有与此类似的最小/目标版本 - 可能您当前的minSdkVersion
为8或更低。
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="19" />